package org.linlinjava.litemall.wxserver.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallMechanism;
import org.linlinjava.litemall.db.domain.LitemallMechanismGoods;
import org.linlinjava.litemall.db.domain.LitemallVoucherCommentVo;
import org.linlinjava.litemall.db.service.LitemallMechanismGoodsService;
import org.linlinjava.litemall.db.service.LitemallMechanismService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.linlinjava.litemall.db.domain.LitemallVoucherComment;
import org.linlinjava.litemall.db.service.LitemallVoucherCommentService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wxs/catalogDetail")
public class WxCatalogDetailController {
    private final Log logger = LogFactory.getLog(WxCatalogDetailController.class);

    @Autowired
    private LitemallMechanismService mechanismService;
    @Autowired
    private LitemallMechanismGoodsService mechanismGoodsService;
    @Autowired
    private LitemallVoucherCommentService voucherCommentService;


    //获取机构详情信息
    @RequestMapping("/getCatalogDetail")
    public Object getCatalogDetail(Integer id) {
        LitemallMechanism mechanism = mechanismService.findById(id);
        List<Map> mechanismGoodList = mechanismGoodsService.getGoodsByMechanismId(id);
        List<LitemallVoucherCommentVo> voucherCommentList = voucherCommentService.voucherCommentList(id);
        List<LitemallVoucherCommentVo> voucherCommentAllList = voucherCommentService.voucherCommentVoAllList(id);

        Map<String, Object> data = new HashMap();
        data.put("mechanismList", mechanism);
        data.put("mechanismGoodList",mechanismGoodList);
        data.put("voucherCommentList",voucherCommentList);
        data.put("length",voucherCommentAllList.size());
        return ResponseUtil.ok(data);
    }

    @RequestMapping("/getVoucherCommentList")
    public Object getVoucherCommentList(Integer id){
        List<LitemallVoucherCommentVo> voucherCommentList = voucherCommentService.voucherCommentVoAllList(id);
        Map<String, Object> data = new HashMap();
        data.put("voucherCommentList",voucherCommentList);
        return ResponseUtil.ok(data);
    }
}
